import sdljava.SDLException;
import sdljava.event.*;


public class ButtonSprite extends Sprite{

	public ButtonSprite(GameWindow gameWindow, ImageData imageData, int x,
			int y, String imageFile) throws SDLException {
		super(gameWindow, imageData, x, y, imageFile);
	}
	
	public boolean spriteHandle(SDLEvent event) throws SDLException{
		if(event.getType() == SDLEvent.SDL_MOUSEMOTION){
			int currentX = ((SDLMouseMotionEvent)event).getX();
			int currentY = ((SDLMouseMotionEvent)event).getY();
			//check if location of cursor is inside button boundaries
			//if inside show the other mouse-over image
			//The image will be in the corresponding vector
			if(currentX >= positionX 
					&& currentY >= positionY 
					&& currentX <= positionX + spriteImageData.width * spriteImageData.zoomx 
					&& currentY <= positionY + spriteImageData.height * spriteImageData.zoomy){
				show(spriteImage.get(1));
				return true;
			}
			else{
				show(spriteImage.get(0));
				return false;
			}
		}
		if(event.getType() == SDLEvent.SDL_MOUSEBUTTONDOWN){
			int currentX = ((SDLMouseButtonEvent)event).getX();
			int currentY = ((SDLMouseButtonEvent)event).getY();
			if(currentX >= positionX 
					&& currentY >= positionY 
					&& currentX <= positionX + spriteImageData.width * spriteImageData.zoomx
					&& currentY <= positionY + spriteImageData.height * spriteImageData.zoomy){
				return true;
			}
		}
		return false;
	}
}
